#!/sbin/openrc-run

description="A multi-client, TLS-only IRC bouncer"

: "${pounce_user:=pounce}"
: "${pounce_group:=pounce}"
: "${pounce_verbose:=false}"
: "${output_log:=/var/log/${RC_SVCNAME}.log}"
: "${error_log:=/var/log/${RC_SVCNAME}.log}"

instance_name="${RC_SVCNAME#*.}"
[ "$instance_name" != "pounce" ] \
    && name="pounce ($instance_name)" \
    || name="pounce"

command=/usr/bin/pounce
command_background="true"
pidfile="/run/${RC_SVCNAME}.pid"
command_user="${pounce_user}:${pounce_group}"

if yesno "${pounce_verbose}"; then
    command_args="-v $pounce_config"
else
    command_args="$pounce_config"
fi

depend() {
    need localmount net
    use dns
}

start_pre() {
    [ -n "$output_log" ] && checkpath -q -f -m 0640 \
        -o "$command_user" "$output_log"

    [ -n "$error_log" ] && checkpath -q -f -m 0640 \
        -o "$command_user" "$error_log"

    [ -n "$pounce_config" ] && checkpath -q -f -m 0640 \
        -o "$command_user" "$pounce_config"
}
